/**
 * @(#)ProcessPageStaticServiceImpl.java 2009-12-23
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.core.services.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.wilmar.process.core.services.api.IProcessPageStaticService;
import com.wilmar.process.dao.api.IProcessPageStaticDAO;
import com.wilmar.process.entity.ProcessPageStatic;
import com.wilmar.process.exception.ObjectNotFoundException;

/**
 * @author asus Email:zhoulibo_java@msn.cn
 * @version 1.0.0
 */
public class ProcessPageStaticServiceImpl implements IProcessPageStaticService {

	private IProcessPageStaticDAO processPageStaticDAO;


	/*
	 * @seecom.wilmar.process.core.services.api.IProcessPageStaticService#
	 * getProcessPageStaticByHistoryTaskId(java.lang.String)
	 */
	public ProcessPageStatic getProcessPageStaticByHistoryTaskId(
			String historyTaskId) throws ObjectNotFoundException {

		return this.processPageStaticDAO
				.getProcessPageStaticByHistoryTaskId(historyTaskId);
	}

	/*
	 * @seecom.wilmar.process.core.services.api.IProcessPageStaticService#
	 * savePageStaticInfo(com.wilmar.process.entity.ProcessPageStatic)
	 */
	public void savePageStaticInfo(ProcessPageStatic pageStatic) {
		this.processPageStaticDAO.save(pageStatic);
	}

	public IProcessPageStaticDAO getProcessPageStaticDAO() {
		return processPageStaticDAO;
	}

	public void setProcessPageStaticDAO(
			IProcessPageStaticDAO processPageStaticDAO) {
		this.processPageStaticDAO = processPageStaticDAO;
	}

	/*
	 * @see
	 * com.wilmar.process.core.services.api.IProcessPageStaticService#writeHtmlPage
	 * (java.lang.String, byte[])
	 */
	public boolean writeHtmlPage(String fileDir, String fileUrl, byte[] fileBytes)
			throws IOException {
		
		File fDir = new File(fileDir);
		File file = new File(fileUrl);
		if (!fDir.exists()) {
			fDir.mkdir();
		}
		if (!file.exists()) {
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
			fos.write(fileBytes);
			fos.close();
			return true;
		}
		return false;
	}
}
